package com.hd123.rumba.qt.def;

import java.io.IOException;

import com.hd123.rumba.exception.BusinessException;

public class SQLUnion {

  private QueryDefinition unionQuery = null;

  public String getSQLClause() throws IOException, ParseException, BusinessException {
    getUnionQuery().setOrders(new SQLOrderList());
    getUnionQuery().setCriteria(query.getSg());
    return getUnionQuery().getSQLClause();
  }

  private QueryDefinition getUnionQuery() throws IOException, ParseException, BusinessException {
    if (unionQuery == null) {
      unionQuery = new QueryDefinition();
      unionQuery.setFile(query.getFile());
      unionQuery.load();
    }
    return unionQuery;
  }

  public String debugInfo() {
    StringBuffer sb = new StringBuffer();
    sb.append(getClass().getName() + "\n");
    sb.append("Name: " + getName() + "\n");
    sb.append("Distinct: " + isDistinct() + "\n");
    return sb.toString();
  }

  private String name;

  private boolean distinct;

  public boolean isDistinct() {
    return distinct;
  }

  public void setDistinct(boolean distinct) {
    this.distinct = distinct;
  }

  public String getName() {
    return name;
  }

  public void setName(String name) {
    this.name = name;
  }

  private QueryDefinition query;

  public QueryDefinition getQuery() {
    return query;
  }

  public void setQuery(QueryDefinition query) {
    this.query = query;
  }
}
